package com.xulin.autocompletetextviewdemo;

import android.os.Bundle;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;

public class AutoCompleteTextViewDemoActivity extends Activity {
    private static final String[] autoStr = new String[] { "Italy","IT","item","its","itself"
    ,"abc","abcd","abcde"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_autocompletetextviewdemo);

        /*预定数据数组传入适配器--------------- autoStr字符串数组传入数组适配器 */
        ArrayAdapter adapter =
                new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, autoStr);
        /*联立布局--------------------AutoCompleteTextView----自动提醒组件   */
        AutoCompleteTextView myAutoCompleteTextView =
                (AutoCompleteTextView) findViewById(R.id.myAutoCompleteTextView);
        /*组件添加内容---------------------自动联想组件 中 添加适配器 */
        myAutoCompleteTextView.setAdapter(adapter);


        //MultiAutoCompleteTextView-------------------输入框一直增加新的选项值
        /**
         *
         * 用MultiAutoCompleteTextView来实现
         * 继承自AutoCompleteTextView，延长AutoCompleteTextView的长度
         * 它和AutoCompleteTextView的区别就是MultiAutoCompleteTextView可以在输入框中一直增加新的选取值。
         * 编写方式也有所不同，在进行setAdapter之后还需要调用setTokenizer(),否则会出现错误----------------
         */
        MultiAutoCompleteTextView myMultiAutoCompleteTextView = (MultiAutoCompleteTextView)
                findViewById(R.id.myMultiAutoCompleteTextView);
        myMultiAutoCompleteTextView.setAdapter(adapter);

        //setTokenizer（分词切分）--------------MultiAuto 比 Auto
        myMultiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
    }
}
